home *** CD-ROM | disk | FTP | other *** search
/ Cracker's Matrix / Cracker's Matrix (nCite Software).iso / Interface / Dispatcher.js < prev    next >
Text File  |  2003-02-24  |  17KB  |  609 lines

  1. /*********************************************************************
  2.  *
  3.  * Macromedia Flash Dispatcher -- a scriptable detector for Flash Player
  4.  *
  5.  *
  6.  * copyright (c) 2000 Macromedia, Inc.
  7.  *
  8.  *********************************************************************/
  9.  
  10.  
  11. /*
  12.  * URL of the Flash self-detecting movie ("sniffer").
  13.  *
  14.  * Reset this if you move the file out of the directory in which the
  15.  * document containing the script that calls MM_FlashDispatch() resides.
  16.  */
  17.  
  18. var MM_FlashSnifferURL = "detectFlash.swf";
  19.  
  20.  
  21. /*
  22.  * Latest available revisions of the Plug-in.
  23.  */
  24.  
  25. var MM_latestPluginRevision = new Object();
  26. MM_latestPluginRevision["6.0"] = new Object();
  27. MM_latestPluginRevision["5.0"] = new Object();
  28. MM_latestPluginRevision["4.0"] = new Object();
  29. MM_latestPluginRevision["3.0"] = new Object();
  30. MM_latestPluginRevision["2.0"] = new Object();
  31.  
  32. /*
  33.  * This table must be updated as new versions and revisions of the
  34.  * plug-in are released, in support of the 'requireLatestRevision'
  35.  * option in MM_FlashDispatch().
  36.  */
  37.  
  38. MM_latestPluginRevision["6.0"]["Windows"] = 79;
  39. MM_latestPluginRevision["6.0"]["Macintosh"] = 79;
  40. MM_latestPluginRevision["6.0"]["Unix"] = 79;
  41.  
  42. MM_latestPluginRevision["5.0"]["Windows"] = 42;
  43. MM_latestPluginRevision["5.0"]["Macintosh"] = 41;
  44. MM_latestPluginRevision["5.0"]["Unix"] = 51;
  45.  
  46. MM_latestPluginRevision["4.0"]["Windows"] = 28;
  47. MM_latestPluginRevision["4.0"]["Macintosh"] = 27;
  48. MM_latestPluginRevision["4.0"]["Unix"] = 12;
  49.  
  50. MM_latestPluginRevision["3.0"]["Windows"] = 10;
  51. MM_latestPluginRevision["3.0"]["Macintosh"] = 10;
  52.  
  53. MM_latestPluginRevision["2.0"]["Windows"] = 11;
  54. MM_latestPluginRevision["2.0"]["Macintosh"] = 11;
  55.  
  56.  
  57. /*
  58.  * MM_FlashInfo() -- construct an object representing Flash Player status
  59.  *
  60.  * Constructor:
  61.  *
  62.  *    new MM_FlashInfo()
  63.  *
  64.  * Properties:
  65.  *
  66.  *    installed        true if player is installed
  67.  *                (undefined if undetectable)
  68.  *
  69.  *    implementation        the form the player takes in this
  70.  *                browser: "ActiveX control" or "Plug-in"
  71.  *
  72.  *    autoInstallable        true if the player can be automatically
  73.  *                installed/updated on this browser/platform
  74.  *
  75.  *    version            player version if installed
  76.  *
  77.  *    revision        revision if implementation is "Plug-in"
  78.  *
  79.  * Methods:
  80.  *
  81.  *    canPlay(contentVersion)    true if installed player is capable of
  82.  *                playing content authored with the
  83.  *                specified version of Flash software
  84.  *
  85.  * Description:
  86.  *
  87.  *    MM_FlashInfo() instantiates an object that contains as much
  88.  *    information about Flash Player--whether it is installed, what
  89.  *    version is installed, and so one--as is possible to collect.
  90.  *
  91.  *    Where Flash Player is implemented as a plug-in and the user's
  92.  *    browser supports plug-in detection, all properties are defined;
  93.  *    this includes Netscape on all platforms and Microsoft Internet
  94.  *    Explorer 5 on the Macintosh.  Where Flash Player is implemented
  95.  *    as an ActiveX control (MSIE on Windows), all properties except
  96.  *    'revision' are defined.
  97.  *
  98.  *    Prior to version 5, Microsoft Internet Explorer on the Macintosh
  99.  *    did not support plug-in detection.  In this case, no properties
  100.  *    are defined, unless the cookie 'MM_FlashDetectedSelf' has been
  101.  *    set, in which case all properties except 'version' and 'revision'
  102.  *    are set.
  103.  *
  104.  *    This object is primarily meant for use by MM_FlashDispatch(), but
  105.  *    may be of use in reporting the player version, etc. to the user.
  106.  */
  107.  
  108. var MM_FlashControlInstalled;    // is the Flash ActiveX control installed?
  109. var MM_FlashControlVersion;    // ActiveX control version if installed
  110.  
  111. function MM_FlashInfo()
  112. {
  113.     if (navigator.plugins && navigator.plugins.length > 0)
  114.     {
  115.     this.implementation = "Plug-in";
  116.     this.autoInstallable = false;    // until Netscape SmartUpdate supported
  117.  
  118.     // Check whether the plug-in is installed:
  119.  
  120.     if (navigator.plugins["Shockwave Flash"])
  121.     {
  122.         this.installed = true;
  123.  
  124.         // Get the plug-in version and revision:
  125.  
  126.         var words =
  127.         navigator.plugins["Shockwave Flash"].description.split(" ");
  128.  
  129.         for (var i = 0; i < words.length; ++i)
  130.         {
  131.         if (isNaN(parseInt(words[i])))
  132.         continue;
  133.  
  134.         this.version = words[i];
  135.         
  136.  
  137.         this.revision = parseInt(words[i + 1].substring(1));
  138.         }
  139.     }
  140.     else
  141.     {
  142.         this.installed = false;
  143.     }
  144.     }
  145.     else if (MM_FlashControlInstalled != null)
  146.     {
  147.     this.implementation = "ActiveX control";
  148.     this.installed = MM_FlashControlInstalled;
  149.     this.version = MM_FlashControlVersion;
  150.     this.autoInstallable = true;
  151.     }
  152.     else if (MM_FlashDetectedSelf())
  153.     {
  154.     this.installed = true;
  155.     this.implementation = "Plug-in";
  156.     this.autoInstallable = false;
  157.     }
  158.  
  159.     this.canPlay = MM_FlashCanPlay;
  160. }
  161.  
  162.  
  163. /*
  164.  * MM_FlashDispatch() -- get Flash Player status and redirect appropriately
  165.  *
  166.  * Synopsis:
  167.  *
  168.  *    MM_FlashDispatch(contentURL, contentVersion, requireLatestRevision,
  169.  *             upgradeURL, install, installURL, altURL,
  170.  *             overridePluginsPage)
  171.  *
  172.  *    Arguments:
  173.  *
  174.  *        contentURL            URL of document containing Flash content
  175.  *
  176.  *        contentVersion        version of Flash software used to
  177.  *                    author content
  178.  *
  179.  *        requireLatestRevision    Boolean indicating whether to require
  180.  *                    latest revision of player (plug-in only)
  181.  *
  182.  *        upgradeURL            document to load if player must be
  183.  *                    upgraded to play content and automated
  184.  *                    updating is not supported on the user's
  185.  *                    browser & platform
  186.  *
  187.  *        install            Boolean indicating whether to install
  188.  *                    if player is not installed
  189.  *
  190.  *        installURL            document to load if 'install' is true
  191.  *                    and automated installation is not
  192.  *                    supported on user's browser & platform
  193.  *
  194.  *        altURL            document to load if 'install' is false
  195.  *
  196.  *        overridePluginsPage        Boolean indicating whether to set the
  197.  *                    PLUGINSPAGE attribute for the embedded
  198.  *                    Flash Player sniffer to `installURL'
  199.  *        disableAutoInstall        Boolean indicating that the auto-installation
  200.  *                    should not occur and that the user will go to the installURL
  201.  *                     or to the upgradeURL as specified
  202.                     
  203.  *
  204.  *    Returns:
  205.  *
  206.  *        Normally, never returns; changes window.location.
  207.  *        Returns with no value when called improperly.
  208.  *
  209.  * Description:
  210.  *
  211.  *    MM_FlashDispatch() detects whether the user's Web browser has the
  212.  *    Flash plug-in or ActiveX control installed, and what version is
  213.  *    installed if so. It then takes appropriate action based on whether
  214.  *    Flash Player is installed and is compatible with 'contentVersion':
  215.  *    load a document containing Flash content, load alternate content,
  216.  *    or oversee the updating or installation of the player.
  217.  *
  218.  *    There are three possible outcomes of the detection process: 
  219.  *
  220.  *        1. A version of Flash Player has been detected that is
  221.  *           suitable for playing the requested content version.
  222.  *           MM_FlashDispatch() will load 'contentURL'.
  223.  *
  224.  *        2. An unsuitable version of Flash Player has been detected.
  225.  *           MM_FlashDispatch() will load 'contentURL' if automated
  226.  *           updating is supported on the user's browser & platform;
  227.  *           otherwise, it will load 'upgradeURL'.
  228.  *
  229.  *        3. Flash Player is not installed.  If 'install' is set to
  230.  *           true, MM_FlashDispatch() will load 'contentURL' if the
  231.  *           user's browser supports automated installation; otherwise,
  232.  *           it will load 'installURL'.  If 'install' is false,
  233.  *           MM_FlashDispatch() will load 'altURL'.
  234.  *
  235.  *    When script-based detection of Flash Player is not possible,
  236.  *    MM_FlashDispatch() attempts to load a Flash movie to carry out
  237.  *    the detection. If Flash Player is not installed, there is presently
  238.  *    no choice but to let the browser redirect the user via the
  239.  *    PLUGINSPAGE attribute of the EMBED tag. In this case, 'install'
  240.  *    is ignored, but setting 'overridePluginsPage' to true will
  241.  *    set PLUGINSPAGE to 'installURL', overriding its default value
  242.  *    (the URL for the Macromedia Flash download center). If this flag
  243.  *    is set, 'installURL' must be absolute, not relative.
  244.  */
  245.  
  246. var MM_FlashPluginsPage = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
  247.  
  248. function MM_FlashDispatch(contentURL, contentVersion, requireLatestRevision,
  249.               upgradeURL, install, installURL, altURL,
  250.               overridePluginsPage,disableAutoInstall)
  251. {
  252.     if (disableAutoInstall == null)
  253.     {
  254.     alert("ERROR: MM_FlashDispatch() called with too few arguments.");
  255.     return;
  256.     }
  257.  
  258.  
  259.     if (overridePluginsPage && installURL.substring(0, 7) != "http://")
  260.     {
  261.     alert("ERROR: MM_FlashDispatch() called with relative URL" +
  262.         " for PLUGINSPAGE (" + installURL + ")");
  263.  
  264.     return;
  265.     }
  266.  
  267.  
  268.     var player = new MM_FlashInfo();
  269.  
  270.     if (player.installed == null)
  271.     {
  272.     var sniffer =
  273.         "<EMBED HIDDEN=\"true\" TYPE=\"application/x-shockwave-flash\"" +
  274.           " WIDTH=\"18\" HEIGHT=\"18\"" +
  275.           " BGCOLOR=\"" + document.bgcolor + "\"" +
  276.           " SRC=\"" + MM_FlashSnifferURL +
  277.             "?contentURL=" + contentURL + "?" +
  278.             "&contentVersion=" + contentVersion +
  279.             "&requireLatestRevision=" + requireLatestRevision +
  280.             "&latestRevision=" +
  281.                 MM_FlashLatestPluginRevision(contentVersion) +
  282.             "&upgradeURL=" + upgradeURL +
  283.             "\"" +
  284.           " LOOP=\"false\" MENU=\"false\"" +
  285.           " PLUGINSPAGE=\"" +
  286.             (overridePluginsPage ? installURL : MM_FlashPluginsPage) +
  287.             "\"" +
  288.         ">" +
  289.         "</EMBED>";
  290.  
  291.     document.open();
  292.     document.write("<HTML><HEAD><TITLE>");
  293.     document.write("Checking for the Flash Player");
  294.     document.write("</TITLE></HEAD>");
  295.     document.write("<BODY BGCOLOR=\"" + document.bgcolor + "\">");
  296.     document.write(sniffer);
  297.     document.write("</BODY>");
  298.     document.write("</HTML>");
  299.     document.close();
  300.     }
  301.     else if (player.installed)
  302.     {
  303.     if (player.canPlay(contentVersion, requireLatestRevision))
  304.     {
  305.         location = contentURL;
  306.     }
  307.     else
  308.     {
  309.     if (disableAutoInstall)
  310.     {
  311.     location = upgradeURL;
  312.     }else
  313.     {
  314.         location = player.autoInstallable ? contentURL : upgradeURL;
  315.     }
  316.     }
  317.     }
  318.     else if (install)
  319.     {
  320.     if (disableAutoInstall){
  321.     location = installURL;
  322.     }
  323.     else{
  324.     location = player.autoInstallable ? contentURL : installURL;
  325.     }
  326.     }
  327.     else
  328.     {
  329.     location = altURL;
  330.     }
  331. }
  332.  
  333.  
  334. /*
  335.  * MM_FlashRememberIfDetectedSelf() -- record that Flash Player detected itself
  336.  *
  337.  * Synopsis:
  338.  *
  339.  *    MM_FlashRememberIfDetectedSelf()
  340.  *    MM_FlashRememberIfDetectedSelf(count)
  341.  *    MM_FlashRememberIfDetectedSelf(count, units)
  342.  *
  343.  *    Arguments:
  344.  *
  345.  *        count        length of time in units before re-checking
  346.  *                whether content can be played (default: 60)
  347.  *
  348.  *        units        unit(s) of time to count: "minute(s)," "hour(s)"
  349.  *                 or "day(s)" (default: "days")
  350.  *
  351.  *
  352.  * Description:
  353.  *
  354.  *    This function conditionally sets a cookie signifying that
  355.  *    the current document was referred via the Dispatcher using
  356.  *    Flash Player self-detection.  It is intended to spare the user
  357.  *    whose browser does not support script-based detection from the
  358.  *    process of Flash Player self-detection on each visit.
  359.  *    
  360.  *    The cookie persists for 60 days, or for the amount of time
  361.  *    specified by the 'count' and 'units' parameters.
  362.  *
  363.  *    If cookies are not being accepted, this function is a no-op;
  364.  *    the Dispatcher will simply attempt Flash Player self-detection
  365.  *    on subsequent visits.
  366.  *
  367.  *    This function must be called from a script embedded in the
  368.  *    document referenced by the 'contentURL' argument to
  369.  *    MM_FlashDispatch().
  370.  *
  371.  */
  372.  
  373. function MM_FlashRememberIfDetectedSelf(count, units)
  374. {
  375.     // the sniffer appends an empty search string to the URL
  376.     // to indicate that it is the referrer
  377.  
  378.     if (document.location.search.indexOf("?") != -1)
  379.     {
  380.     if (!count) count = 60;
  381.     if (!units) units = "days";
  382.  
  383.     var msecs = new Object();
  384.  
  385.     msecs.minute = msecs.minutes = 60000;
  386.     msecs.hour = msecs.hours = 60 * msecs.minute;
  387.     msecs.day = msecs.days = 24 * msecs.hour;
  388.  
  389.     var expires = new Date();
  390.  
  391.     expires.setTime(expires.getTime() + count * msecs[units]);
  392.  
  393.     document.cookie =
  394.         'MM_FlashDetectedSelf=true ; expires=' + expires.toGMTString();
  395.     }
  396. }
  397.  
  398.  
  399. /*
  400.  * MM_FlashDemur() -- record user's decision not to install Flash Player
  401.  *
  402.  * Synopsis:
  403.  *
  404.  *    MM_FlashDemur()
  405.  *    MM_FlashDemur(count)
  406.  *    MM_FlashDemur(count, units)
  407.  *
  408.  *    Arguments:
  409.  *
  410.  *        count    length of time in units to remember decision
  411.  *            (default: 60)
  412.  *
  413.  *        units    unit(s) of time to count: "minute(s)," "hour(s)"
  414.  *            or "day(s)" (default: "days")
  415.  *
  416.  *    Returns:
  417.  *
  418.  *        true if successful; false otherwise.
  419.  *
  420.  * Description:
  421.  *
  422.  *    MM_FlashDemur() sets a cookie signifying that the user requested
  423.  *    that the decision not to install Flash be remembered.
  424.  *
  425.  *    The cookie persists for 60 days, or for the amount of time
  426.  *    specified by the 'count' and 'units' parameters.
  427.  *
  428.  *    This function may be used as the handler for the 'onClick' event
  429.  *    associated with the user's selecting a link to alternate content.
  430.  *    If cookies are not being accepted, it will return false; this
  431.  *    may be used to control whether the link is followed.
  432.  */
  433.  
  434. function MM_FlashDemur(count, units)
  435. {
  436.     if (!count) count = 60;
  437.     if (!units) units = "days";
  438.  
  439.     var msecs = new Object();
  440.  
  441.     msecs.minute = msecs.minutes = 60000;
  442.     msecs.hour = msecs.hours = 60 * msecs.minute;
  443.     msecs.day = msecs.days = 24 * msecs.hour;
  444.  
  445.     var expires = new Date();
  446.  
  447.     expires.setTime(expires.getTime() + count * msecs[units]);
  448.  
  449.     document.cookie =
  450.     'MM_FlashUserDemurred=true ; expires=' + expires.toGMTString();
  451.  
  452.  
  453.     if (!MM_FlashUserDemurred())
  454.     {
  455.     alert("Your browser must accept cookies in order to " +
  456.           "save this information.  Try changing your preferences.");
  457.  
  458.     return false;
  459.     }
  460.     else
  461.     return true;
  462. }
  463.  
  464.  
  465. /*
  466.  * MM_FlashUserDemurred() -- recall user's decision not to install Flash Player
  467.  *
  468.  * Synopsis:
  469.  *
  470.  *    MM_FlashUserDemurred()
  471.  *
  472.  *    Returns:
  473.  *
  474.  *        true if a cookie signifying that the user declined to install
  475.  *        Flash Player is set; false otherwise.
  476.  *
  477.  * Description:
  478.  *
  479.  *    This function is useful in determining whether to set the 'install'
  480.  *    flag when calling MM_FlashDispatch().  If true, it means that the
  481.  *    user's previous decision not to install Flash Player should be
  482.  *    honored, i.e., 'install' should be set to false.
  483.  */
  484.  
  485. function MM_FlashUserDemurred()
  486. {
  487.     return (document.cookie.indexOf("MM_FlashUserDemurred") != -1);
  488. }
  489.  
  490.  
  491. /*********************************************************************
  492.  * THE FOLLOWING FUNCTIONS ARE NOT PUBLIC.  DO NOT CALL THEM DIRECTLY.
  493.  *********************************************************************/
  494.  
  495. /*
  496.  * MM_FlashLatestPluginRevision() -- look up latest Flash Player plug-in
  497.  *                     revision for this platform
  498.  *
  499.  * Synopsis:
  500.  *
  501.  *    MM_FlashLatestPluginRevision(playerVersion)
  502.  *
  503.  *    Arguments:
  504.  *
  505.  *        playerVersion    plug-in version to look up revision of
  506.  *
  507.  *    Returns:
  508.  *
  509.  *        The latest available revision of the specified version of
  510.  *        the Flash Player plug-in on this platform, as an integer;
  511.  *        undefined for versions before 2.0.
  512.  *
  513.  * Description:
  514.  *
  515.  *    This look-up function is only intended to be called internally.
  516.  */
  517.  
  518. function MM_FlashLatestPluginRevision(playerVersion)
  519. {
  520.     var latestRevision;
  521.     var platform;
  522.  
  523.     if (navigator.appVersion.indexOf("Win") != -1)
  524.     platform = "Windows";
  525.     else if (navigator.appVersion.indexOf("Macintosh") != -1)
  526.     platform = "Macintosh";
  527.     else if (navigator.appVersion.indexOf("X11") != -1)
  528.     platform = "Unix";
  529.  
  530.     latestRevision = MM_latestPluginRevision[playerVersion][platform];
  531.  
  532.     return latestRevision;
  533. }
  534.  
  535.  
  536. /*
  537.  * MM_FlashCanPlay() -- check whether installed Flash Player can play content
  538.  *
  539.  * Synopsis:
  540.  *
  541.  *    MM_FlashCanPlay(contentVersion, requireLatestRevision)
  542.  *
  543.  *    Arguments:
  544.  *
  545.  *        contentVersion        version of Flash software used to
  546.  *                    author content
  547.  *
  548.  *        requireLatestRevision    Boolean indicating whether latest
  549.  *                    revision of plug-in should be required
  550.  *
  551.  *    Returns:
  552.  *
  553.  *        true if the installed player can play the indicated content;
  554.  *        false otherwise.
  555.  *
  556.  * Description:
  557.  *
  558.  *    This function is not intended to be called directly, only
  559.  *    as an instance method of MM_FlashInfo.
  560.  */
  561.  
  562. function MM_FlashCanPlay(contentVersion, requireLatestRevision)
  563. {
  564.     var canPlay;
  565.  
  566.     if (this.version)
  567.     {
  568.     canPlay = (parseInt(contentVersion) <= this.version);
  569.  
  570.     if (requireLatestRevision)
  571.     {
  572.         if (this.revision &&
  573.         this.revision < MM_FlashLatestPluginRevision(this.version))
  574.         {
  575.         canPlay = false;
  576.         }
  577.     }
  578.     }
  579.     else
  580.     {
  581.     canPlay = MM_FlashDetectedSelf();
  582.     }
  583.  
  584.     return canPlay;
  585. }
  586.  
  587.  
  588. /*
  589.  * MM_FlashDetectedSelf() -- recall whether Flash Player has detected itself
  590.  *
  591.  * Synopsis:
  592.  *
  593.  *    MM_FlashDetectedSelf()
  594.  *
  595.  *    Returns:
  596.  *
  597.  *        true if a cookie signifying that Flash Player has detected itself
  598.  *        is set; false otherwise.
  599.  *
  600.  * Description:
  601.  *
  602.  *    This function is only meant to be called internally.
  603.  */
  604.  
  605. function MM_FlashDetectedSelf()
  606. {
  607.     return (document.cookie.indexOf("MM_FlashDetectedSelf") != -1);
  608. }
  609.